<?php
namespace app\admin\model;
use think\Model;

class User extends model{
	function findall($username,$password){
		// 后台1,总监2,大股东3,股东4,总代5,代理6,会员7
		$num = $this->where('types','NEQ',7)->where(['username'=>$username,'password'=>$password])->find();
		return $num;
	}
	function findtopuser($id){
		$res = $this->where('topuser',$id)->order('id desc')->select();
		return $res;
	}
	function findtopuser1($id){
		$res = db('user')->where('topuser',$id)->order('id desc')->select();
		foreach ($res as $key => $r) {
			$topname[] = $res[$key]['id']; 
		}
		return $topname;
	}
	function findusername($username,$types,$topuser){
		$res = db('user')->where('types',$types)->where('topuser',$topuser)->where('username','like',"%".$username."%")->select();
		return $res;
	}
	function judgeusers($id){
		$res = $this->where('id',$id)->where('topuser',0)->where('types',1)->count();
		return $res;
	}
	function finuser($types){
		// 找在线的某人数
		$res = $this->where('status','EQ',1)->where('types',$types)->count();
		return $res;
	}
	function finduser($type){
		$res = db('user')->where('types',$type)->select();
		foreach ($res as $key => $r) {
			$topname = db('user')->where('id',$r['topuser'])->find();
			$res[$key]['topusername'] = $topname['username']; 
		}
		return $res;
	}
	function finduserid($id){
		$res = db('user')->where('id',$id)->select();
		foreach ($res as $key => $r) {
			$topname = db('user')->where('id',$r['topuser'])->find();
			$res[$key]['topusername'] = $topname['username']; 
		}
		return $res;
	}
	function findtype($type){
		$res = db('user')->where('types',$type)->select();
		return $res;
	}
	function findalls($username){
		$res = $this->where('username',$username)->count();
		return $res;
	}
	function findallsbo($username){
		$res = db('user')->where('username',$username)->select();
		$uid = $res['0']['id'];
		return $uid;
	}
	function findhoutaizz(){
		$res = $this->where('status','EQ',1)->where('types',1)->where('topuser',1)->count();
		return $res;
	}
	function findscount(){
		// 找在线总人数
		$res = $this->where('status','EQ',1)->count();
		return $res;
	}
	function selectuser(){
		// 具体在线人的信息
		$res = $this->where('status',1)->select();
		// mp($res);
		return $res;
	}
	function discover(){
		$res = $this->select();
		return $res;
	}
	function findid($id){
		$res= $this->where('id',$id)->find();
		return $res;
	}
	function findhoutai($id){
		// 确认后台和子账户 yes 返回true 或 no 返回false
		$res = $this->where('id',$id)->find();
		if($res['types']==1 || $res['types']==7){
			return true;
		}
		return false;
	}
	function findupoccupy($id){
		$res = db('user u')->where('id',$id)->field('u.upoccupy')->find();
		return $res;
	}
	function findtop($id){
		$res= db('user u')->where('id',$id)->field('u.topuser')->find();
		return $res;
	}
	function findmoneys($id){
		$res = db('user u')->where('id',$id)->field('u.moneys')->find();
		return $res;
	}
	function findshang($id){
		$res = db('user u')->where('id',$id)->field('u.topuser')->select();
		return $res;
	}
}